#include <staff/common/Value.h>
#include <rise/common/Log.h>
#include "Message.h"

namespace smq
{
  staff::CDataObject& operator<<(staff::CDataObject& rdoParam, const MessageHeader& rstStruct)
  {
    rdoParam.CreateChild("sId", rstStruct.sId);
    rdoParam.CreateChild("sQueue", rstStruct.sQueue);
    rdoParam.CreateChild("sPublisher", rstStruct.sPublisher);
    return rdoParam;
  }

  staff::CDataObject& operator>>(staff::CDataObject& rdoParam, MessageHeader& rstStruct)
  {
    rstStruct.sId = rdoParam.GetChildByLocalName("sId").GetText();
    rstStruct.sQueue = rdoParam.GetChildByLocalName("sQueue").GetText();
    rstStruct.sPublisher = rdoParam.GetChildByLocalName("sPublisher").GetText();
    return rdoParam;
  }

  staff::CDataObject& operator<<(staff::CDataObject& rdoParam, const Message& rstStruct)
  {
    rdoParam << static_cast<const MessageHeader&>(rstStruct);
    staff::CDataObject rdoParamtdoMessage = rdoParam.CreateChild("Message");
    rdoParamtdoMessage.AppendChild(const_cast<staff::CDataObject&>(rstStruct.tdoMessage));
    return rdoParam;
  }

  staff::CDataObject& operator>>(staff::CDataObject& rdoParam, Message& rstStruct)
  {
    rdoParam >> static_cast<MessageHeader&>(rstStruct);
    rstStruct.tdoMessage = rdoParam.GetChildByLocalName("Message").Begin()->DetachNode();
    return rdoParam;
  }
}

